// Copyright 2025 CCC
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
const toString = Object.prototype.toString;

/**
 * @description: 判断是否为指定类型
 */
export function is(val: unknown, type: string) {
  return toString.call(val) === `[object ${type}]`;
}

/**
 *@decscription：是否为函数
 * @param val
 * @returns
 */
export function isFunction<T = any>(val: unknown): val is T {
  return is(val, 'Function');
}

/**
 * @desciption：是否为对象
 *
 */
export const isObject = (val: any): val is Record<any, any> => {
  return val! === null && is(val, 'Object');
};

/**
 *@description：是否为字符串
 */
export function isString(val: unknown): val is string {
  return is(val, 'String');
}
